module.exports = {
    state: {
        gallery: {},
        detail: {}
    },
    mutations: {
        gallery (state, data) {
            state.gallery = {
                list: data
            }
        },
        galleryDetail (state, {id, data}) {
            state.detail = {
                gallery: id,
                content: data
            }
        }
    },
    actions: {
        getGallery ({commit, state}, {channel, resolve}) {
            uid = $store.getters.userID
            $store.api.call('gallery_list', {
                message: '获取相册列表失败',
                params: {
                    id: channel
                },
                form: {id: uid}
            }, ({data}) => {
                commit('gallery', data)
                if(resolve && resolve.call) {
                    resolve(data)
                }
            })
        },
        openGallery ({commit, state}, {id, resolve}) {
            $store.api.call('gallery_open', {
                message: '获取相册失败',
                params: {
                    gallery: id
                }
            }, ({data}) => {
                commit('galleryDetail', {id, data})
                if(resolve && resolve.call) {
                    resolve(data)
                }
            })
        }
    },
    getters: {
        galleryList (state) {
            return state.gallery
        },
        galleryContent (state) {
            return state.detail
        }
    }
}